package com.yubest.security.controller;

import com.yubest.security.bean.Response;
import com.yubest.security.bean.UserInfo;
import com.yubest.security.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private TokenService tokenService;

    @PreAuthorize("@ps.hasPermit('testx')")
    @GetMapping(value = "/testx")
    public Response<Void> test1() {
        return Response.ok(null);
    }

    @PreAuthorize("@ps.hasPermit('test2')")
    @GetMapping(value = "/test2")
    public Response<Void> test2() {
        return Response.ok(null);
    }

    @PreAuthorize("@ps.hasPermit('test3')")
    @GetMapping(value = "/test3")
    public Response<Void> test3() {
        return Response.ok(null);
    }

    @PreAuthorize("@ps.hasPermit('info')")
    @GetMapping(value = "/info")
    public Response<UserInfo> info() {
        UserInfo userInfo = tokenService.getCurrentUser();
        return Response.ok(userInfo);
    }

}
